package com.example.memberships

import android.os.Bundle
import androidx.activity.viewModels
import androidx.appcompat.app.AppCompatActivity
import com.alibaba.android.arouter.facade.annotation.Route
import com.blankj.utilcode.util.ToastUtils
import com.example.common.view.view.BaseMvvmActivity
import com.example.memberships.databinding.ActivityMembershipsBinding
import com.example.memberships.vm.MemViewModel
import dagger.hilt.android.AndroidEntryPoint

@AndroidEntryPoint
@Route(path = "/memberships/MembershipsActivity")
class MembershipsActivity : BaseMvvmActivity<ActivityMembershipsBinding>() {

    private val memberShipsViewModel:MemViewModel by viewModels()

    override fun initView() {
        memberShipsViewModel.getMemberShip(58)
        memberShipsViewModel.mMemSuccess.observe(this){
            mDataBinding.textView7.text=it.membershipLevel
        }
        mDataBinding.btnUpMember.setOnClickListener {
            if (mDataBinding.textView7.text=="黄金会员") {
                memberShipsViewModel.getMemberUp("铂金会员",1119)
                mDataBinding.textView7.text="铂金会员"
            }else  if (mDataBinding.textView7.text=="铂金会员") {
                memberShipsViewModel.getMemberUp("钻石会员",1119)
                mDataBinding.textView7.text="钻石会员"
            }else  if (mDataBinding.textView7.text=="钻石会员") {
                ToastUtils.showLong("已经是最高等级会员")
            }
            memberShipsViewModel.mMemUpSuccess.observe(this){
                ToastUtils.showLong("升级成功")
            }
        }
        mDataBinding.rg.setOnCheckedChangeListener { group, checkedId ->
            when(checkedId){
                R.id.rb1->{
                    mDataBinding.rb1.isChecked=true
                    mDataBinding.rb2.isChecked=false
                    mDataBinding.rb3.isChecked=false
                }
                R.id.rb2->{
                    mDataBinding.rb1.isChecked=false
                    mDataBinding.rb2.isChecked=true
                    mDataBinding.rb3.isChecked=false
                }
                R.id.rb3->{
                    mDataBinding.rb1.isChecked=false
                    mDataBinding.rb2.isChecked=false
                    mDataBinding.rb3.isChecked=true
                }
            }
            if (mDataBinding.rb1.isChecked){
                memberShipsViewModel.getMemberShip(58)
                mDataBinding.tv1.text="商家0.9折"
                mDataBinding.tv2.text="100积分可抵1元"
                mDataBinding.tv3.text="10元停车券"
            }else if (mDataBinding.rb2.isChecked){
                memberShipsViewModel.getMemberShip(59)
                mDataBinding.tv1.text="商家0.85折"
                mDataBinding.tv2.text="80积分可抵1元"
                mDataBinding.tv3.text="15元停车券"
            }else{
                memberShipsViewModel.getMemberShip(60)
                mDataBinding.tv1.text="商家0.8折"
                mDataBinding.tv2.text="50积分可抵1元"
                mDataBinding.tv3.text="20元停车券"
            }
        }
    }
    override fun onResume() {
        super.onResume()
        memberShipsViewModel.getMember(1666)
    }
    override fun getLayoutId(): Int =R.layout.activity_memberships
}